package com.jichangxiu.main;

import com.jichangxiu.utils.git.GitUtils;
import com.jichangxiu.utils.maven.MavenUtils;

import java.io.File;
import java.net.URL;

/**
 * @author Jcx
 * @date 2022/12/23 9:08
 */
public class Main {

    public static void main(String[] args) {
        URL url = MavenUtils.class.getClassLoader().getResource("repository");
        if (url != null) {
            String gitUrl = "https://gitee.com/jichangxiu/Jcx-Jar.git";
            String gitUsername = "87984498@qq.com";
            String gitPassword = "hz981225";
            String projectName = "Jcx-Jar";
            String projectPath = url.getPath() + File.separator + projectName;
            File projectFile = new File(projectPath);
            if (projectFile.exists()) {
                boolean master = GitUtils.pull(gitUsername, gitPassword, projectPath, "master");
                System.out.println("拉取最新代码：：：" + master);
            } else {
                Boolean master = GitUtils.cloneRepository(gitUsername, gitPassword, gitUrl, "master", projectFile.getPath());
                System.out.println("获取代码仓库：：：" + master);
            }

            Boolean doClean = MavenUtils.doClean(projectPath);
            System.out.println("清理项目：：：" + doClean);

            Boolean doPackage = MavenUtils.doPackage(projectPath);
            System.out.println("打包项目：：：" + doPackage);

            if (doPackage) {
                String packagePath = projectPath + File.separator + "target";
                String jarPath = packagePath + File.separator + projectName + ".jar";
                if (new File(jarPath).exists()) {
                    System.out.println(jarPath);
                }
            }

        }
    }

}
